package com.example.zhuzehua.controller;

import com.example.zhuzehua.entity.TbGoods;
import com.example.zhuzehua.entity.TbUser;
import com.example.zhuzehua.entity.TbUserinfo;
import com.example.zhuzehua.service.TbUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("user")
public class TbUserController {
    @Autowired
    private TbUserService tbUserService;
    @RequestMapping(value="/findAll",method = RequestMethod.GET)
    public List<TbUser> findAll(){
        return  tbUserService.findAll();
    }
    @RequestMapping(value="/add",method=RequestMethod.POST)
    public String add(@RequestBody TbUser user){
        return tbUserService.add(user);
    }
    @RequestMapping(value="/update",method=RequestMethod.POST)
    public  String updateUser(@RequestBody TbUser user){
        return  tbUserService.updateUser(user);}
    @RequestMapping(value="/del",method=RequestMethod.GET)
    public  String delUser(@RequestParam int id){
        return tbUserService.delUser(id);}
    @RequestMapping(value="/queryByName",method=RequestMethod.POST)
    public List<TbUser> queryByName(@RequestBody TbUser user){
        return tbUserService.queryByName(user);}
    @RequestMapping(value="/queryLikeName",method=RequestMethod.POST)
    public  List<TbUser> queryLikeName(@RequestBody TbUser user){
        return tbUserService.queryLikeName(user);}
    @RequestMapping(value="/queryTiaojiao",method=RequestMethod.POST)
    public  List<TbUser> queryTiaojiao(@RequestBody TbUser user){
        return  tbUserService.queryTiaojiao(user);}
    @RequestMapping(value="/login",method=RequestMethod.POST)
    public String login(@RequestBody TbUserinfo userinfo){
        return tbUserService.login(userinfo);}
    @RequestMapping(value="/fenye",method=RequestMethod.GET)
    public List<TbUser>fenye(@Param("pageNum")int pageNum, @Param("pageSize")int pageSize){
        return tbUserService.findAllFenye(pageNum,pageSize);}
    @RequestMapping(value="/findwendu",method=RequestMethod.GET)
    public List<TbGoods> findwendu(){
        return tbUserService.findAllWendu();
    }
    @RequestMapping(value="/findgoodsByType",method=RequestMethod.GET)
    public List<TbGoods> findgoodsByType(@Param("type")int type){
        return tbUserService.findAllGoodsByType(type);}
}

